package com.example.yml0528;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import androidx.fragment.app.Fragment;

import com.example.yml.R;

import java.util.ArrayList;
import java.util.List;


public class OneFragment extends Fragment {

    List<ShangPin> splist;
    ListAdapter adapter;
    int[] imgi = {R.mipmap.tou3,R.mipmap.tou5, R.mipmap.tou9,R.mipmap.tou10, R.mipmap.tou11};
    String[] zuozhe={"李白","杜甫","白居易","李清照","王昌龄","泰戈尔"};

    public OneFragment() {
        init();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_one, container, false);
        ListView tv = view.findViewById(R.id.lv);

        adapter = new ListAdapter(splist, inflater);
        tv.setAdapter(adapter);
        return view;
    }

    public void init() {
        splist = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            ShangPin sp = new ShangPin();
            sp.setName("作者:" + zuozhe[i]);
            sp.setImg(imgi[i]);
            sp.setJianjie("详  情");
            sp.setPrice("价钱："+5.0 + i*5+"人民币");
            splist.add(sp);
        }

    }

}
